/* 
 * File:   vector.cpp
 * Author: gian
 * 
 * Created on April 17, 2012, 10:10 AM
 */

#include "vector.hpp"

// complex vector

cvector::cvector(unsigned int n) {
    v = gsl_vector_complex_alloc(n);
}

cvector::cvector(const cvector& orig) {
    v = gsl_vector_complex_alloc(orig.size());
    for(unsigned int i=0;i<v->size;i++) {
        gsl_vector_complex_set(v,i,gsl_vector_complex_get(orig.v,i));
    }
}

cvector::~cvector() {
    gsl_vector_complex_free(v);
}

void cvector::set(size_t i, double re, double im)
{
    gsl_complex val;
    GSL_SET_COMPLEX(&val,re,im);
    gsl_vector_complex_set(v,i,val);
}

gsl_complex cvector::get(size_t i) const {
    return gsl_vector_complex_get(v,i);
}

size_t cvector::size() const {
    return v->size;
}

void cvector::resize(unsigned int n)
{
  if(n != v->size) {
    gsl_vector_complex_free(v);
    v = NULL;
    v = gsl_vector_complex_alloc(n);
  }
}


// vector

vector::vector(unsigned int n) {
    v = gsl_vector_alloc(n);
}

vector::vector(const vector& orig) {
    v = gsl_vector_alloc(orig.size());
    for(unsigned int i=0;i<v->size;i++) {
        gsl_vector_set(v,i,gsl_vector_get(orig.v,i));
    }
}

vector::~vector() {
    gsl_vector_free(v);
}

void vector::set(size_t i, double val)
{
  gsl_vector_set(v,i,val);
}

double vector::get(size_t i) const {
    return gsl_vector_get(v,i);
}

size_t vector::size() const {
    return v->size;
}

void vector::resize(unsigned int n)
{
  if(n != v->size) {
    gsl_vector_free(v);
    v = NULL;
    
    v = gsl_vector_alloc(n);
  }
}

// complex float vector

cvectorf::cvectorf(unsigned int n) {
    v = gsl_vector_complex_float_alloc(n);
}

cvectorf::cvectorf(const cvectorf& orig) {
    v = gsl_vector_complex_float_alloc(orig.size());
    for(unsigned int i=0;i<v->size;i++) {
        gsl_vector_complex_float_set(v,i,gsl_vector_complex_float_get(orig.v,i));
    }
}

cvectorf::~cvectorf() {
    gsl_vector_complex_float_free(v);
}

void cvectorf::set(size_t i, float re, float im)
{
  gsl_complex_float val;
  GSL_SET_COMPLEX(&val,re,im);
  gsl_vector_complex_float_set(v,i,val);
}

gsl_complex_float cvectorf::get(size_t i) const {
    return gsl_vector_complex_float_get(v,i);
}

size_t cvectorf::size() const {
    return v->size;
}

void cvectorf::resize(unsigned int n)
{
  if(n != v->size) {
    gsl_vector_complex_float_free(v);
    v = NULL;
    v = gsl_vector_complex_float_alloc(n);
  }
}

// vector float

vectorf::vectorf(unsigned int n) {
    v = gsl_vector_float_alloc(n);
}

vectorf::vectorf(const vectorf& orig) {
    v = gsl_vector_float_alloc(orig.size());
    for(unsigned int i=0;i<v->size;i++) {
        gsl_vector_float_set(v,i,gsl_vector_float_get(orig.v,i));
    }
}

vectorf::~vectorf() {
    gsl_vector_float_free(v);
}

void vectorf::set(size_t i, float val)
{
  gsl_vector_float_set(v,i,val);
}

float vectorf::get(size_t i) const {
    return gsl_vector_float_get(v,i);
}

size_t vectorf::size() const {
    return v->size;
}

void vectorf::resize(unsigned int n)
{
  if(n != v->size) {
    gsl_vector_float_free(v);
    v = NULL;    
    v = gsl_vector_float_alloc(n);
  }
}
